﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Adge.BLL;
using Adge.Models;
using Adge.Common;
using NHibernate.Expression;

namespace Adge.Web.UI
{
    public partial class MoreFiles : BasePage
    {
        private Int32 CatId
        {
            get
            {
                Int32 _catId = -1;
                if (Request["catid"] != null)
                {
                    Int32.TryParse(Request["catid"], out _catId);
                }
                return _catId;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                InitCatAndFileList();
            }
        }

        private void InitCatAndFileList()
        {
            AdgeArBase<CategoryInfo> bllCat = new AdgeArBase<CategoryInfo>();
            CategoryInfo cat = bllCat.GetEntityById(CatId);            
            if (cat != null)
            {
                litTitle.Text = cat.Catname;
                AdgeArBase<AttachmentInfo> catlist = new Adge.BLL.AdgeArBase<AttachmentInfo>();
                ICriterion[] criterias = new ICriterion[] { new EqExpression("AdgeInfoCategory", cat) };
                Order[] orders = new Order[] { Order.Asc("AttOrder") };
                AttachmentInfo[] entities = catlist.SlicedFindAll(0, AdgeConfig.MaxRecordNumber, orders, criterias);
                clFiles.DataSource = entities;
                clFiles.DataBind();
            }
        }       

        protected void PageIndexChanged(object source, DataGridPageChangedEventArgs e)
        {
            clFiles.CurrentPageIndex = e.NewPageIndex;
            clFiles.DataBind();
            //clNews.SetPage(e.NewPageIndex);
        }
    }
}
